﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using GestureSaver;
using System.IO;

namespace Experimenter
{
    public static class RotationWork
    {
        public static void DoWork()
        {
            string path = @"C:\Users\admin\Dropbox\Gesture_Recognition_MVaA\@Experiments\Rotation\RotationDB\Testing";

            GestureDB db = new GestureDB(path);

            Common.CenterizeAllGestures(db);
            Common.RectificateAllProjectiveMotionDistortion(db);

            using (TextWriter writer = File.CreateText(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + @"\result3.txt"))
            {
                for (int i = 0; i < db.TotalClassCount; i++)
                {
                    double betweenClass = 0;
                    double withinClass = 0;

                    for (int j = 0; j < db.TotalClassCount; j++)
                    {
                        double sumDTW = 0;

                        for (int k = 0; k < db[i].Count; k++)
                        {
                            for (int l = 0; l < db[j].Count; l++)
                            {
                                sumDTW += Common.DTW(db[i][k], db[j][l], Common.SelectedJoints);
                            }
                        }

                        if (i == j)
                        {
                            withinClass = sumDTW;
                        }
                        else
                        {
                            betweenClass += sumDTW;
                        }

                        writer.WriteLine(db[i][0].gestureType + " ---> " + db[j][0].gestureType + "     " + sumDTW);
                        writer.Flush();
                    }

                    betweenClass /= (db.TotalClassCount - 1);

                    writer.WriteLine(db[i][0].gestureType + "    " + "Within class: " + withinClass + "   " +
                        "Between class: " + betweenClass + "     " + "Ratio: " + betweenClass / withinClass);
                }
            }        
        }            
    }
}
